package ba.unsa.etf.pikks.objekti;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;


public class PredProcesiranje {
	
	String fileName;
	String codeLine;
	String className;
	public int line_number;
	boolean blank_line;
	public HashMap<Integer,String> methodMap;

	public PredProcesiranje(File file) throws Exception {
		methodMap=new HashMap<Integer, String>();	
		
		Scanner diskScanner = new Scanner(file);
		while (diskScanner.hasNext()) {
			readLine(diskScanner.nextLine());
		}
	}

	public HashMap<Integer,String> getMethodMap(){
		return methodMap;	
	}
	
	public void readLine(String input)  {

		line_number++;
		codeLine = input.trim();
		blank_line=false;

		if (codeLine.length() == 0 | codeLine == ";") blank_line = true;

		if (!blank_line & codeLine.length() >= 2) {
			int m=codeLine.indexOf("/" + "*");
			int n=codeLine.indexOf("*" + "/");
			int t=codeLine.indexOf("//");
			if(m==-1&&n==-1&&t==-1){
			if (codeLine.indexOf(" class ") >= 0){
				methodMap.put(line_number, codeLine);
				int begin=codeLine.indexOf("class");
				int end=codeLine.indexOf("{");
				if(end==-1)
					end=codeLine.length();
				className=codeLine.substring(begin+6, end);
				String[] temp=className.split(" ");
				className=temp[0];
				}
			}

			int x=codeLine.indexOf("public");
			int y=codeLine.indexOf("private");
			int z=codeLine.indexOf("protected");
			if(x>=0||y>=0||z>=0){

				int comma=codeLine.indexOf(";");
				
				if((codeLine.indexOf(")") >= 0)
						&&(codeLine.indexOf("(") >= 0)
						&& (comma==-1)
						&& (m==-1||m>x||m>y||m>z)
						&& (n==-1||n>x||n>y||n>z)
						&& (t==-1||t>x||t>y||t>z))
						 {
							methodMap.put(line_number, codeLine);
				}
			}
		}

	}

}
